package com.example.lianxi222.fragment.live;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.example.mvvm_base.base.viewmodel.BaseViewModel;
import com.example.mvvm_base.net.Const;
import com.example.mvvm_base.userbean.FollowEntity;
import com.example.mvvm_base.userbean.GiftEntity;
import com.example.mvvm_base.userbean.LikeEntity;
import com.example.mvvm_base.userbean.Money;
import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class LiveViewModel extends BaseViewModel<LiveRepo> {

     MutableLiveData<FollowEntity> followS=new MutableLiveData<>();
     MutableLiveData<String> followF=new MutableLiveData<>();
    MutableLiveData<FollowEntity> unfollowS=new MutableLiveData<>();
    MutableLiveData<String> unfollowF=new MutableLiveData<>();
    MutableLiveData<GiftEntity> giftS=new MutableLiveData<>();
    MutableLiveData<String> giftF=new MutableLiveData<>();
    MutableLiveData<Money> moneyS=new MutableLiveData<>();
    MutableLiveData<String> moneyF=new MutableLiveData<>();


    public void follow(String name){
        HashMap<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTH_NAME,name);
        String json=new Gson().toJson(map);
        RequestBody requestBody=RequestBody.create(MediaType.parse("application/json;charset=utf-8"),json);
        repo.follow(requestBody,followS,followF);
    }
    public void cancel_follow(String name){
        HashMap<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTH_NAME,name);
        String json=new Gson().toJson(map);
        RequestBody requestBody=RequestBody.create(MediaType.parse("application/json;charset=utf-8"),json);
        repo.cancelFollow(requestBody,unfollowS,unfollowF);
    }
    public void getGift(){
        repo.getGift(giftS,giftF);
    }
    public void getMoney(String username){
        repo.getMoney(username,moneyS,moneyF);
    }
    public void updateMoney(Money money){
        repo.updateMoney(money);
    }


    public LiveViewModel(@NonNull Application application) {
        super(application);
    }

    @Override
    protected LiveRepo createRepo() {
        return new LiveRepo();
    }
}
